package com.campusify.controller;


import com.campusify.compents.ApiResponse;
import com.campusify.compents.PageResult;
import com.campusify.pojo.Jobrecruitment;
import com.campusify.service.JobRecruitmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * controller
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/jobRecruitment")
public class JobRecruitmentController {

	@Autowired
	private JobRecruitmentService jobRecruitmentService;
	
	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findAll")
	public List<Jobrecruitment> findAll(){
		return jobRecruitmentService.findAll();
	}
	
	
	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findPage")
	public PageResult  findPage(int page,int rows){			
		return jobRecruitmentService.findPage(page, rows);
	}
	
	/**
	 * 增加
	 * @param jobRecruitment
	 * @return
	 */
	@RequestMapping("/add")
	public ApiResponse add(@RequestBody Jobrecruitment jobRecruitment){
		try {
			jobRecruitmentService.add(jobRecruitment);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}
	
	/**
	 * 修改
	 * @param jobRecruitment
	 * @return
	 */
	@RequestMapping("/update")
	public ApiResponse update(@RequestBody Jobrecruitment jobRecruitment){
		try {
			jobRecruitmentService.update(jobRecruitment);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}	
	
	/**
	 * 获取实体
	 * @param id
	 * @return
	 */
	@RequestMapping("/findOne")
	public Jobrecruitment findOne(Integer jobID){
		return jobRecruitmentService.findOne(jobID);		
	}
	
	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delete")
	public ApiResponse delete(Integer [] jobIDs){
		try {
			jobRecruitmentService.delete(jobIDs);
			return ApiResponse.success(null); 
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}
	
		/**
	 * 查询+分页
	 * @param brand
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/search")
	public PageResult search(@RequestBody Jobrecruitment jobRecruitment, int page, int rows  ){
		return jobRecruitmentService.findPage(jobRecruitment, page, rows);		
	}
	
}
